package summary;

import java.util.List;

/**
 * @Author: 海琳琦
 * @Date: 2022/7/7 17:25
 */
public class Title841II {

    private static int count;

    public boolean canVisitAllRooms(List<List<Integer>> rooms) {
        count = 0;
        int n = rooms.size();
        int[] visited = new int[n];
        dfs(rooms, visited, 0);
        return count == n;
    }

    private void dfs(List<List<Integer>> rooms, int[] visited, int roomId) {
        if (visited[roomId] == 1) {
            return;
        }
        visited[roomId] = 1;
        count++;
        List<Integer> keys = rooms.get(roomId);
        for (Integer room : keys) {
            dfs(rooms, visited, room);
        }
    }

    public static void main(String[] args) {

    }
}
